package com.luck.easyfoodbatch.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.luck.easyfoodbatch.R;
import com.luck.easyfoodbatch.custom.FlowLayout;
import com.luck.easyfoodbatch.entity.CityEntity;
import com.luck.easyfoodbatch.indexablelistview.IndexBarAdapter;
import com.luck.easyfoodbatch.util.T;
import com.luck.easyfoodbatch.util.Tools;

/**
 * Created by YoKeyword on 16/3/20.
 */
public class CityAdapter extends IndexBarAdapter<CityEntity> {
    private Context mContext;
    public onResetLocation onResetLocation;

    public interface onResetLocation {
        void onResetLocationBack();
    }

    public CityAdapter(Context context, onResetLocation onResetLocation) {
        mContext = context;
        this.onResetLocation = onResetLocation;
    }

    public CityAdapter(Context context) {
        mContext = context;
    }

    @Override
    protected TextView onCreateTitleViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_tv_title_city, parent, false);
        return (TextView) view.findViewById(R.id.tv_title);
    }

    @Override
    protected ViewHolder onCreateViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_city, parent, false);
        return new CityViewHolder(view);
    }


    @Override
    protected void onBindViewHolder(ViewHolder holder, CityEntity cityEntity) {
        CityViewHolder cityViewHolder = (CityViewHolder) holder;
        if (cityEntity.getFirstSpell().equals("定")) {
            cityViewHolder.iv_refresh.setVisibility(View.VISIBLE);
            if (Tools.isNull(cityEntity.getName())) {
                cityViewHolder.tvCity.setText("定位中，请稍候...");
            } else {
                cityViewHolder.tvCity.setText(cityEntity.getName());
            }
        } else {
            cityViewHolder.tvCity.setText(cityEntity.getName());
        }
        cityViewHolder.iv_refresh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onResetLocation.onResetLocationBack();
            }
        });

    }


    class CityViewHolder extends IndexBarAdapter.ViewHolder {
        TextView tvCity;
        ImageView iv_refresh;
        RelativeLayout relativeLayout;

        public CityViewHolder(View view) {
            super(view);
            tvCity = (TextView) view.findViewById(R.id.tv_name);
            iv_refresh = (ImageView) view.findViewById(R.id.iv_refresh);
            relativeLayout = (RelativeLayout) view.findViewById(R.id.rl_city);
        }
    }

}